<template>
  <div class="department" id="department">
    <!-- 右侧 -->
    <div class="department_right">
      <!-- 顶部导航栏 -->
      <div class="mechanism_nav">
        <!-- 左侧 -->
        <div class="mechanism_nav_left">
          <el-radio-group
            v-model="radio"
            size="small"
            @change="modelType($event)"
          >
            <el-radio-button label="待办"></el-radio-button>
            <el-radio-button label="已办"></el-radio-button>
            <!-- #2b5a9d -->
          </el-radio-group>
        </div>
        <!-- 顶部按钮 -->
        <div class="print">
          <div class="printTable">
            <el-button
              type="primary"
              icon="el-icon-refresh"
              size="small"
              @click="yj_searchForm(getList)"
            ></el-button>
            <el-button
              type="primary"
              icon="el-icon-circle-plus-outline"
              size="small"
              v-if="getList.modelType == '0' && yj_add == true"
              @click="edit('新增')"
            >
              新增
            </el-button>
            <el-button
              type="primary"
              icon="el-icon-edit"
              size="small"
              v-if="getList.modelType == '0' && yj_edit == true"
              @click="edit('编辑')"
            >
              编辑
            </el-button>
            <el-button
              type="primary"
              icon="el-icon-circle-check"
              size="small"
              v-if="getList.modelType == '0' && yj_send == true"
              @click="SubmitText(fId)"
            >
              下发
            </el-button>
            <el-button
              type="primary"
              icon="el-icon-edit"
              size="small"
              v-if="getList.modelType == '0' && yj_check == true"
              @click="edit('回复')"
            >
              回复
            </el-button>
            <el-button
              type="primary"
              icon="el-icon-delete"
              size="small"
              v-if="getList.modelType == '0' && yj_delete == true"
              @click="rowDelete(fId)"
            >
              删除
            </el-button>
          </div>
        </div>
      </div>

      <!-- 表格 -->
      <div class="text_table">
        <tableData
          :height="navigatepageNums > 1 ? 'calc(100% - 50px)' : '100%'"
          :config="table_config"
          :dataList="tableData"
          :loading="loading"
          @selection-change="selectionChange"
          @sort-change="sortChange"
          @click-change="rowChange"
          @ClickOnLine="yj_viewForm"
          :page="getList.page"
          :pageSize="getList.pageSize"
        />
        <pagination
          v-if="navigatepageNums > 1"
          :info="queryCriteriaData"
          :treelength="treelength"
          :total="queryCriteriaData.total"
          :pageNum.sync="getList.page"
          :limit.sync="getList.pageSize"
          @pagination="yj_searchForm(getList)"
        />
      </div>
      <!--弹框-->
      <div class="Control-1 mechanism_dialogS closure">
        <el-dialog
          :title="dialogTitle"
          :modal-append-to-body="false"
          v-dialogDrag
          :visible.sync="dialogEditVisible"
          v-loading="loadingEditDialog"
          element-loading-text="拼命加载中"
          element-loading-spinner="el-icon-loading"
          element-loading-background="rgba(0, 0, 0, 0.2)"
        >
          <div
            class="dialogBody common"
            :style="{ height: '650px' }"
            style="overflow: hidden"
          >
            <div style="overflow-y: auto; margin-bottom: 20px; height: 100%">
              <div class="baseTitle">质量工作在线沟通</div>
              <div class="publicForm" style="height: 180px; overflow-y: auto">
                <publicForm
                  ref="publicForm"
                  lableWidth="110px"
                  :formObj="FromShow"
                  :formData="formData"
                  :timestamp="formData.fFileurl"
                  :fileList="fSourcefileList"
                  @selectChange="selectChange"
                  @inputChange="inputChange"
                  @delteFile="delteFile"
                  @inputFocus="inputFocus"
                >
                </publicForm>
              </div>
              <div class="baseTitle" v-if="Sign == '回复' || Sign == '查看'">
                问题处理情况
              </div>
              <div
                class="publicForm"
                v-if="Sign == '回复' || Sign == '查看'"
                style="height: 100px; overflow-y: auto"
              >
                <publicForm
                  ref="publicForm1"
                  lableWidth="110px"
                  :formObj="putAway"
                  :formData="formData"
                  :timestamp="formData.fCheckfile"
                  :fileList="fCheckfileList"
                  @selectChange="selectChange"
                  @inputChange="inputChange"
                  @delteFile="delteFile1"
                  @inputFocus="inputFocus"
                >
                </publicForm>
              </div>

              <div style="height: 50px"></div>
            </div>
          </div>
          <div class="newlyAdded_btn" v-if="btnShow">
            <el-button
              type="primary"
              @click="yj_saveForm('回复')"
              v-if="Sign == '回复'"
            >
              保存
            </el-button>

            <el-button
              type="primary"
              @click="yj_saveForm(0)"
              v-if="Sign == '新增' || Sign == '编辑'"
            >
              保存
            </el-button>
            <el-button type="warning" @click="dialogEditVisible = false">
              关闭
            </el-button>
          </div>
        </el-dialog>
      </div>
      <!--机构树 -->
      <div
        class="Control-1 mechanism_dialogS closure treeData"
        id="department1"
      >
        <el-dialog
          :title="TreeNameTitle"
          :modal-append-to-body="false"
          v-dialogDrag
          :visible.sync="dialogEditVisibleTree"
          v-loading="loadingEditDialogTree"
          element-loading-text="拼命加载中"
          element-loading-spinner="el-icon-loading"
          element-loading-background="rgba(0, 0, 0, 0.2)"
        >
          <div
            class="dialogBody common"
            :style="{ height: '650px' }"
            style="overflow: hidden"
          >
            <div style="overflow-y: auto; margin-bottom: 50px; height: 100%">
              <tree
                style="height: 100%"
                :treeData="treeData"
                :checkData="checkData"
                nodeKey="fCompanyid"
                @getTreeInfo="handleNodeClick"
                :defaultProps="defaultProps"
              >
              </tree>
            </div>
          </div>
          <div class="newlyAdded_btn">
            <el-button type="primary" @click="yj_saveForm('树')"
              >保存</el-button
            >

            <el-button type="warning" @click="dialogEditVisibleTree = false"
              >关闭</el-button
            >
          </div>
        </el-dialog>
      </div>
    </div>
  </div>
</template>
<script>
import {
  getWorkonlineCommunicatePageLists, //列表
  getWorkonlineCommunicateByFid, //详情
  saveWorkonlineCommunicate, //保存
  saveWorkonlineCommunicateByCheck, //回复
  deleteWorkonlineCommunicate, //删除
  commitWorkonlineCommunicate, //提交
  getPersonLists, //获取网格员
  getUserCompanyTreeListXm, //受检项目树
  getUserCompanyTreeLists, //受检单位树
} from "@/api/request.js";
import tree from "@/components/siteQualityPage/QualityGridManage/tree"; //左侧机构树
import TableData from "@/components/stationProductionPage/HntManage/el-tables"; //主页面列表
import Pagination from "@/components/public/el-pagination"; //主页面分页
import publicForm from "@/components/public/el-form.vue"; //弹框form
// import publicOne from "@/components/QualityGridManage/workOrder/el-form.vue"; //弹框form
import formJs from "./regexDetail.js"; //新增弹框配置项
// import tree from "@/components/public/el-trees"; //左侧机构树

export default {
  // inject: ["reload"],
  name: "communicateText",
  data() {
    return {
      name: "communicateText",
      // 分页
      navigatepageNums: null, //是否显示分页
      queryCriteriaData: {},
      // 分页
      yj_add: null,
      yj_edit: null,
      yj_delete: null,
      yj_send: null,
      yj_check: null,

      radio: "待办",

      // 列表
      getList: {
        fCompanyid: "", // 左侧选中组织机构id
        fCheckunit: "", //涉及单位
        fCheckproject: "", //项目部名称
        fGridmantype: "", //网格员类别
        page: 1, // 当前页码
        pageSize: 20, // 每页显示条数
        userId: "", // 查询待办或已办时传 列表页查询不传
        modelType: "0", // 0-待办 1-已办 传2 表示列表页查询
      },
      fId: null, //当前行数据fId
      row: { fstatus: "" }, //选中行
      loading: false, //列表转载
      table_config: formJs.table_config,
      tableData: [], //表格列表数据列表
      // 列表

      // 弹框
      Sign: "",
      timeYMD: null, //当前日期
      btnShow: true,
      dialogTitle: "",
      loadingEditDialog: false, //弹框loading
      dialogEditVisible: false, //新增弹框是否显示
      FromShow: formJs.FromShowText, //下发
      FromShowText: formJs.FromShowText, //下发---编辑
      FromShowLook: formJs.FromShowLook, //下发---查看

      putAway: formJs.putAwayText, //处理情况
      putAwayText: formJs.putAwayText, //处理情况---编辑
      putAwayLook: formJs.putAwayLook, //处理情况---查看
      formData: formJs.formData,
      CcpeoplesUserList: [], //复选人员框
      recordfiles: [], //删除文件
      fSourcefileList: [],
      fCheckfileList: [],

      saveData: {},
      gridmanList: [], //所有网格员
      // 机构树
      dialogEditVisibleTree: false,
      loadingEditDialogTree: false,
      checked: true, //查看下级按钮
      companyTree: "", //所有数据
      treeData: [], //左侧树状图数据
      checkData: [], //树状图默认选中id
      treeRow: { fCompanyids: null }, //选中树数据--受检项目
      treeRows: null, //选中树数据--受检单位
      defaultProps: {
        children: "children",
        label: "fShortname",
      },
      highlightBd: true, //左侧机构树停留背景色
      treeText: {
        companyId: null,
        userId: null,
        text: null,
      },
      TreeNameTitle: null,
      // 机构树

      userInfo: {}, //登录用户
    };
  },
  components: {
    TableData, //主页面列表
    Pagination, //分页
    publicForm, //表单
    // publicOne,
    tree, //机构树
  },
  created() {},
  mounted() {
    this.userInfo = JSON.parse(sessionStorage.getItem("userInfo"));
    // console.log("userInfo", this.userInfo);
    this.getList = {
      fCompanyid: this.userInfo.companyId, // 左侧选中组织机构id
      userId: this.userInfo.userId, // 查询待办或已办时传 列表页查询不传
      page: 1, //页码
      pageSize: 20, //每页条数
      modelType: "0", // 0代办 1已办 不传或传空 表示列表页查询
      fCheckunit: "", //涉及单位
      fCheckproject: "", //项目部名称
      fGridmantype: "", //网格员类别
    };

    this.getData();
    this.yj_searchForm(this.getList);
    this.btnRole(this.name);

    this.table_config.operation.cols = [
      {
        prop: "fstatus",
        type: "primary",
        handleRow: this.handleRow,
      },
    ];
    this.table_config.operation["specialClass"] = function (rowData) {
      var color = null;
      if (rowData == "执行中") {
        color = "orange !important";
      } else if (rowData == "已结束") {
        color = "green !important";
      } else {
        color = "#409eff !important";
      }
      return color;
    };
  },
  methods: {
    btnRole(name) {
      var btnList = [];
      var ModuleList = JSON.parse(sessionStorage.getItem("ModuleList"));
      if (ModuleList.length > 0) {
        ModuleList.map((item) => {
          if (item.fEncode == name) {
            btnList = item.modulebuttonList;
          }
        });
        var btnStr = [];
        btnList.map((item) => {
          btnStr.push(item.fEncode);
        });
        this.yj_add = btnStr.includes("yj_add");
        this.yj_edit = btnStr.includes("yj_edit");
        this.yj_delete = btnStr.includes("yj_delete");
        this.yj_send = btnStr.includes("yj_send");
        this.yj_check = btnStr.includes("yj_check");
      } else {
        this.yj_add = true;
        this.yj_edit = true;
        this.yj_delete = true;
        this.yj_send = true;
        this.yj_check = true;
      }
    },
    modelType(e) {
      this.fId = "";
      if (e == "待办") {
        this.getList.modelType = "0";
        this.getList.userId = this.userInfo.userId;
      } else {
        this.getList.modelType = "1";
        this.getList.userId = this.userInfo.userId;
      }
      this.yj_searchForm(this.getList);
    },
    // 获取列表数据
    yj_searchForm(id) {
      this.row = { fstatus: "" }; //选中行
      this.fId = "";
      this.loading = true;
      getWorkonlineCommunicatePageLists(id)
        .then((res) => {
          if (res.errcode == 0) {
            var that = this;
            that.loading = false;
            that.tableData = res.data.pageInfo.list;
            that.queryCriteriaData = res.data.pageInfo;
            that.navigatepageNums =
              that.queryCriteriaData.navigatepageNums.length;
          } else {
            this.$message.error("列表", res.msg);
            this.loading = false;
          }
        })
        .catch(() => {
          this.loading = false;
        });
    },
    // 新增/编辑/回复
    edit(title) {
      this.Sign = title;
      this.dialogTitle = title;
      this.recordfiles = [];
      this.fSourcefileList = [];
      this.btnShow = true;
      this.FromShow = this.FromShowText;
      if (title == "新增") {
        this.newData = [];
        this.checkboxGroup1 = [];
        var fFileurl = "GZZLZXGT" + new Date().valueOf();
        this.formData = {
          fId: "",
          fProjectid: this.userInfo.projectId,
          fProjectname: this.userInfo.projectName,
          fCompanyid: this.userInfo.companyId,
          fCompanyname: this.userInfo.companyName,
          fModifyuserid: "",
          fModifydate: null,
          fModifyusername: "",
          fCheckunit: "", //涉及单位
          fCheckunitid: "", //涉及单位id
          fCheckproject: "", //涉及项目
          fCheckprojectid: "", //涉及项目
          fGridmantype: "", //网格员类别
          fSubgridmanid: "", //指定网格员id
          fSubgridmanname: "", //指定网格员姓名
          fProblemdescription: "", //存在问题简述
          fFileurl: fFileurl, //相关现场资料
          fHasproblemdates: this.timeYMD, //发现问题日期
          fReportname: this.userInfo.realName, // 填报人姓名
          fReportid: this.userInfo.userId, // 填报人id
          fReportdates: this.timeYMD, //填报日期
          fCheckresult: "", //处理结果
          fCheckfile: "", //处理过程相关资料
          fCheckdescription: "", //问题处理简述
          fGridmanid: "", //网格员id
          fGridmanname: "", //网格员姓名
          fCheckdates: "", //完成日期
          fStatus: "", //信息状态
          fIsdeleted: "",
          userId: this.userInfo.userId, //当前登录人id
          userName: this.userInfo.realName, //当前登录人姓名
        };
        this.dialogEditVisible = true;
      } else if (title == "回复") {
        if (this.fId == "" || this.fId == null) {
          this.$message.error("请先选择需要回复的数据");
        } else {
          if (this.row.fstatus == "执行中") {
            this.FromShow = this.FromShowLook;
            this.putAway = this.putAwayText;

            this.loadingEditDialog = true; //弹框loading
            this.dialogEditVisible = true;
            this.getConcrete(this.fId);
          } else {
            this.$message.error("请选择信息状态为‘执行中’的数据");
          }
        }
      } else if (title == "编辑") {
        if (this.fId == "" || this.fId == null) {
          this.$message.error("请先选择需要编辑的数据");
        } else {
          if (this.row.fstatus == "编辑中") {
            this.loadingEditDialog = true; //弹框loading
            this.dialogEditVisible = true;
            this.getConcrete(this.fId);
          } else {
            this.$message.error("请选择信息状态为‘编辑中’的数据");
          }
        }
      }
    },
    // 获取详情
    getConcrete(id) {
      getWorkonlineCommunicateByFid({ fId: id })
        .then((res) => {
          if (res.errcode == 0) {
            this.loadingEditDialog = false; //弹框loading
            this.formData = res.data.yjQmpMsWorkonlineCommunicate;
            this.fSourcefileList = res.data.fFileurllist; //在线沟通相关资料
            // this.fCheckfileList = res.data.fCheckfilelist; //处理过程相关资料
            if (this.Sign == "回复") {
              // 指定网格员
              if (
                this.formData.fGridmanid == "" ||
                this.formData.fGridmanid == null ||
                this.formData.fGridmanname == "" ||
                this.formData.fGridmanname == null
              ) {
                this.formData.fGridmanname = this.userInfo.realName;
                this.formData.fGridmanid = this.userInfo.userId;
              }
              // 完成日期
              if (
                this.formData.fCheckdates == "" ||
                this.formData.fCheckdates == null
              ) {
                this.formData.fCheckdates = this.timeYMD;
              }

              //相关附件资料
              if (
                this.formData.fCheckfile == "" ||
                this.formData.fCheckfile == null
              ) {
                var fCheckfile = "GZZLZXGTHF" + new Date().valueOf();
                this.formData.fCheckfile = fCheckfile;
              }
            } else {
              //附件资料
              if (
                this.formData.fFileurl == "" ||
                this.formData.fFileurl == null
              ) {
                var fFileurl = "GZZLZXGT" + new Date().valueOf();
                this.formData.fFileurl = fFileurl;
              }

              //项目名称
              if (
                this.formData.fProjectname == "" ||
                this.formData.fProjectname == null ||
                this.formData.fProjectid == "" ||
                this.formData.fProjectid == null
              ) {
                this.formData.fProjectname = this.userInfo.projectName; // 项目名称
                this.formData.fProjectid = this.userInfo.projectId;
              }
              //标段名称
              if (
                this.formData.fCompanyname == "" ||
                this.formData.fCompanyname == null ||
                this.formData.fCompanyid == "" ||
                this.formData.fCompanyid == null
              ) {
                this.formData.fCompanyname = this.userInfo.companyName; // 标段名称
                this.formData.fCompanyid = this.userInfo.companyId;
              }
              //发现问题日期
              if (
                this.formData.fHasproblemdates == "" ||
                this.formData.fHasproblemdates == null
              ) {
                this.formData.fHasproblemdates = this.timeYMD; // 检查日期起始
              }
              //填报人
              if (
                this.formData.fReportname == "" ||
                this.formData.fReportname == null ||
                this.formData.fReportid == "" ||
                this.formData.fReportid == null
              ) {
                this.formData.fReportname = this.userInfo.realName;
                this.formData.fReportid = this.userInfo.userId;
              }
              //当前登录人
              if (
                this.formData.userName == "" ||
                this.formData.userName == null ||
                this.formData.userId == "" ||
                this.formData.userId == null
              ) {
                this.formData.userName = this.userInfo.realName;
                this.formData.userId = this.userInfo.userId;
              }
              //填报日期
              if (
                this.formData.fReportdates == "" ||
                this.formData.fReportdates == null
              ) {
                this.formData.fReportdates = this.timeYMD;
              }
            }
          } else {
            this.loadingEditDialog = false; //弹框loading
            return this.$message.error(res.msg);
          }
        })
        .catch((err) => {
          console.log(err);
        });
    },

    // 保存
    yj_saveForm(num) {
      if (num == 0) {
        if (this.$refs.publicForm.submitForm()) {
          this.saveData = {
            fId: this.formData.fId, //传fid代表修改 不传代表新增
            fProjectname: this.userInfo.projectName, // 当前登录人项目名称
            fProjectid: this.userInfo.projectId, // 当前登录人项目ID
            fCompanyname: this.userInfo.companyName, // 当前登录人标段名称
            fCompanyid: this.userInfo.companyId, // 当前登录人标段ID
            fCheckunit: this.formData.fCheckunit, //涉及单位
            fCheckunitid: this.formData.fCheckunitid, //涉及单位id
            fCheckproject: this.formData.fCheckproject, //涉及项目
            fCheckprojectid: this.formData.fCheckprojectid, //涉及项目id
            fGridmantype: this.formData.fGridmantype, //网格员类别
            fSubgridmanid: this.formData.fSubgridmanid, //指定网格员id
            fSubgridmanname: this.formData.fSubgridmanname, //指定网格员姓名
            fProblemdescription: this.formData.fProblemdescription, //存在的问题概述
            fFileurl: this.formData.fFileurl, //相关现场资料
            fHasproblemdates: this.formData.fHasproblemdates, //发现问题日期
            fReportid: this.formData.fReportid, //填报人id'
            fReportname: this.formData.fReportname, //填报人姓名
            fReportdates: this.formData.fReportdates, //填报时间
            userId: this.userInfo.userId, //当前登录人id
            userName: this.userInfo.realName, // 当前登录人名称
            recordfiles: this.recordfiles, // 删除文件id集合
          };
          saveWorkonlineCommunicate(this.saveData)
            .then((res) => {
              if (res.errcode == 0) {
                this.yj_searchForm(this.getList);
                this.dialogEditVisible = false;
                this.$message.success("新增成功");
              } else {
                this.$message.error(res.msg);
                console.log("接口报错");
              }
            })
            .catch((error) => {
              console.log(error);
            });
        } else {
          console.log("error");
        }
      } else if (num == "回复") {
        if (this.$refs.publicForm1.submitForm()) {
          if (this.fCheckfileList.length != 0) {
            var saveData1 = {
              fId: this.formData.fId, //传fid代表修改 不传代表新增
              fCheckresult: this.formData.fCheckresult, //处理结果
              fCheckfile: this.formData.fCheckfile, //处理过程相关资料
              fCheckdescription: this.formData.fCheckdescription, //问题处理简述
              fGridmanid: this.formData.fGridmanid, //网格员id
              fGridmanname: this.formData.fGridmanname, //网格员姓名
              fCheckdates: this.formData.fCheckdates, //完成日期
              recordfiles: this.recordfiles, // 删除文件id集合
            };
            saveWorkonlineCommunicateByCheck(saveData1)
              .then((res) => {
                if (res.errcode == 0) {
                  this.yj_searchForm(this.getList);
                  this.dialogEditVisible = false;
                  this.$message.success("签收成功");
                } else {
                  this.$message.error(res.msg);
                  console.log("签收接口报错");
                }
              })
              .catch((error) => {
                console.log(error, "签收接口报错");
              });
          } else {
            this.$message.error("请上传处理过程相关资料");
          }
        } else {
          console.log("error");
        }
      } else if (num == "树") {
        this.formData.fSubgridmanname = "";
        this.formData.fSubgridmanid = "";

        // 受检单位
        if (this.propText == "fCheckunit") {
          if (this.treeRows != null) {
            if (this.formData.fCheckunit != this.treeRows.fFullname) {
              this.formData.fCheckproject = "";
              this.formData.fCheckprojectid = "";
              this.formData.fSubgridmanname = "";
              this.formData.fSubgridmanid = "";
              this.FromShowText[3].placeholder = "请先填写涉及项目和网格员类别";
              this.FromShowText[3].options = [];
            }
            this.formData.fCheckunit = this.treeRows.fFullname;
            this.formData.fCheckunitid = this.treeRows.fCompanyid;
          } else {
            this.$message.warning("请选择受检单位");
          }
        }

        // 受检项目
        if (this.propText == "fCheckproject") {
          this.formData.fCheckproject = this.treeRow.fShortname;
          this.formData.fCheckprojectid = this.treeRow.fCompanyid;
          console.log(this.formData.fGridmantype);
          if (
            this.formData.fGridmantype != "" &&
            this.formData.fGridmantype != null &&
            this.formData.fCheckprojectid != "" &&
            this.formData.fCheckprojectid != null
          ) {
            this.getGridman();
          } else {
            this.FromShowText[3].placeholder = "请先填写涉及项目和网格员类别";
            this.FromShowText[3].options = [];
          }
        }
        this.dialogEditVisibleTree = false;
      }
    },
    // 下发
    SubmitText(id) {
      if (id != "" && id != null) {
        if (this.row.fstatus == "编辑中") {
          this.$confirm("是否继续下发?", "提示", {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: "warning",
          })
            .then(() => {
              this.loading = true;
              commitWorkonlineCommunicate({
                fId: id,
                userId: this.userInfo.userId,
                userName: this.userInfo.realName,
              })
                .then((res) => {
                  if (res.errcode == 0) {
                    this.loading = false;
                    this.yj_searchForm(this.getList);
                    this.$message.success("下发成功");
                  } else {
                    this.$message.error("下发失败", res.msg);
                    this.loading = false;
                  }
                })
                .catch(() => {
                  console.log("下发失败");
                  this.loading = false;
                });
            })
            .catch(() => {
              this.$message("取消下发");
            });
        } else {
          return this.$message.error("请选择信息状态为‘编辑中’的数据");
        }
      } else {
        return this.$message.error("请先选择需要下发的数据");
      }
    },
    // 删除
    rowDelete(id) {
      if (id != "" && id != null) {
        if (this.row.fstatus == "编辑中") {
          this.$confirm("此操作将永久删除该数据, 是否继续?", "提示", {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: "warning",
          })
            .then(() => {
              this.loading = true;
              deleteWorkonlineCommunicate({ fId: id })
                .then((res) => {
                  if (res.errcode == 0) {
                    this.loading = false;
                    this.yj_searchForm(this.getList);
                    this.$message.success("删除成功");
                  } else {
                    this.$message.error("删除失败", res.msg);
                    this.loading = false;
                  }
                })
                .catch(() => {
                  console.log("删除失败");
                  this.loading = false;
                });
            })
            .catch(() => {
              this.$message("取消删除");
            });
        } else {
          return this.$message.error("请选择信息状态为‘编辑中’的数据");
        }
      } else {
        return this.$message.error("请先选择需要删除的数据");
      }
    },

    // 点击查看
    yj_viewForm(row, label) {
      this.row = row;
      this.fId = row.fId;
      if (label == "涉及单位") {
        this.editText(this.fId);
      }
    },
    // 查看
    editText(id) {
      this.FromShow = this.FromShowLook;
      this.putAway = this.putAwayLook;

      this.dialogTitle = "查看";
      this.Sign = "查看";
      this.btnShow = false;
      if (id != "" && id != null) {
        this.loadingEditDialog = true; //弹框loading
        this.dialogEditVisible = true;
        getWorkonlineCommunicateByFid({ fId: id })
          .then((res) => {
            if (res.errcode == 0) {
              var that = this;
              that.loadingEditDialog = false;
              that.fSourcefileList = res.data.fFileurllist; //工作指令资料附件
              that.fCheckfileList = res.data.fCheckfilelist; //工作指令资料附件
              that.formData = res.data.yjQmpMsWorkonlineCommunicate;
            } else {
              this.$message.error("查看", res.msg);
              this.loadingEditDialog = false;
            }
          })
          .catch(() => {
            console.log("查看---详情接口报错");
            this.loadingEditDialog = false;
          });
      } else {
        return this.$message.error("请先选择需要查看的数据");
      }
    },
    getData() {
      var time = new Date();
      const y = time.getFullYear();
      const m = (time.getMonth() + 1 + "").padStart(2, "0");
      const d = (time.getDate() + "").padStart(2, "0");
      this.timeYMD = `${y}-${m}-${d}`;
    },
    // 点击当前
    rowChange(val) {
      this.row = val;
      this.fId = val.fId;
    },
    // 刪除
    delteFile(file) {
      for (let index = 0; index < this.fSourcefileList.length; index++) {
        if (file.uid == this.fSourcefileList[index].uid) {
          if (this.fSourcefileList[index].atta == undefined) {
            this.recordfiles.push({
              fId: this.fSourcefileList[index].fId,
            });
          } else {
            this.recordfiles.push({
              fId: this.fSourcefileList[index].atta.fId,
            });
          }
          this.fSourcefileList.splice(index, 1);
        }
      }
    },
    delteFile1(file) {
      for (let index = 0; index < this.fCheckfileList.length; index++) {
        if (file.uid == this.fCheckfileList[index].uid) {
          if (this.fCheckfileList[index].atta == undefined) {
            this.recordfiles.push({
              fId: this.fCheckfileList[index].fId,
            });
          } else {
            this.recordfiles.push({
              fId: this.fCheckfileList[index].atta.fId,
            });
          }
          this.fCheckfileList.splice(index, 1);
        }
      }
    },
    inputChange(value, index, prop) {
      // console.log("inputChange", value, index, prop);
      return value, index, prop;
    },
    inputFocus(index, prop) {
      // console.log("inputFocus", index, prop);
      this.propText = prop;
      // 受检单位
      if (prop == "fCheckunit") {
        this.TreeNameTitle = "选择受检单位";
        this.getTrees(this.userInfo.companyId);
      }
      // 受检项目
      if (prop == "fCheckproject") {
        this.TreeNameTitle = "选择受检项目";
        if (
          this.formData.fCheckunitid != "" &&
          this.formData.fCheckunitid != null
        ) {
          this.getTree(this.formData.fCheckunitid);
        } else {
          this.$message.warning("请先选择涉及单位");
        }
      }
    },
    selectChange(value, index, prop) {
      console.log(this.formData.fGridmantype);
      // console.log("selectChange", value, index, prop);
      if (prop == "fGridmantype") {
        if (
          this.formData.fGridmantype != "" &&
          this.formData.fGridmantype != null &&
          this.formData.fCheckprojectid != "" &&
          this.formData.fCheckprojectid != null
        ) {
          this.formData.fSubgridmanid = ""; //指定网格员id
          this.formData.fSubgridmanname = ""; //指定网格员姓名
          this.getGridman();
        } else {
          this.FromShowText[3].placeholder = "请先填写涉及项目和网格员类别";
          this.FromShowText[3].options = [];
        }
      }
      if (prop == "fSubgridmanname") {
        this.gridmanList.map((item) => {
          if (value == item.fChargeusername) {
            this.formData.fSubgridmanid = item.fChargeuserid;
          }
        });
      }
    },
    //弹框--- 树结构
    getTrees(id) {
      var treeText = {
        companyId: id,
        userId: this.userInfo.userId,
      };
      this.loadingEditDialogTree = true;
      getUserCompanyTreeLists(treeText)
        .then((res) => {
          if (res.errcode == 0) {
            this.dialogEditVisibleTree = true;
            this.loadingEditDialogTree = false;
            var companyTree = res.data.userCompanyTreeList;
            this.treeData = this.commonJs.tranListToTreeData(companyTree);

            if (
              this.formData.fPatrolprojectid != "" &&
              this.formData.fPatrolprojectid != null
            ) {
              this.checkData[0] = this.formData.fPatrolprojectid;
            }
          } else {
            this.$message.error(res.msg);
            this.loadingEditDialogTree = false;
            // this.$message.error("获取组织机构失败");
            return false;
          }
        })
        .catch(() => {
          this.loadingEditDialogTree = false;
          return false;
        });
    },
    getTree(id) {
      var treeText = {
        companyId: id,
        userId: this.userInfo.userId,
      };
      this.loadingEditDialogTree = true;
      getUserCompanyTreeListXm(treeText)
        .then((res) => {
          if (res.errcode == 0) {
            this.dialogEditVisibleTree = true;
            this.loadingEditDialogTree = false;
            var companyTree = res.data.userCompanyTreeList;
            this.treeData = this.commonJs.tranListToTreeData(companyTree);
            if (
              this.formData.fPatrolprojectid != "" &&
              this.formData.fPatrolprojectid != null
            ) {
              this.checkData[0] = this.formData.fPatrolprojectid;
            }
          } else {
            this.$message.error(res.msg);
            this.loadingEditDialogTree = false;
            // this.$message.error("获取组织机构失败");
            return false;
          }
        })
        .catch(() => {
          this.loadingEditDialogTree = false;
          return false;
        });
    },
    handleNodeClick(data) {
      // 受检单位
      if (this.propText == "fCheckunit") {
        this.treeRows = data;
      }
      // 受检项目
      if (this.propText == "fCheckproject") {
        this.treeRow = data;
      }
    },

    //弹框--- 树结构
    // 获取指定网格员
    getGridman() {
      this.FromShowText[3].options = [];
      var treeText = {
        fQualitygridclass: this.formData.fGridmantype, //质量网格类别
        fCompanyid: this.formData.fCheckprojectid, //项目id
      };
      getPersonLists(treeText)
        .then((res) => {
          if (res.errcode == 0) {
            this.gridmanList = res.data;
            var manList = { value: "", label: "" };
            res.data.map((item) => {
              manList = {
                value: item.fChargeusername,
                label: item.fChargeusername,
              };

              console.log(888, manList);
              this.FromShowText[3].options.push(manList);
            });
            this.FromShowText[3].placeholder = "请选择指定网格员";
          } else {
            this.$message.error(res.msg);
            return false;
          }
        })
        .catch(() => {
          this.loadingEditDialogTree = false;
          return false;
        });
    },
    // 获取指定网格员

    // 多选方法
    selectionChange() {},
    // 排序方法
    sortChange() {},
  },
};
</script>

<style scoped lang="less">
.printTables {
  background: #fff;
  display: flex;
  justify-content: end;
  padding: 5px;
  margin-top: 10px;
}

.dialogBody {
  padding: 3px 20px;
  height: 80%;
  overflow-y: auto;
}

.baseTitle {
  /* border: 1px solid #0c204d; */
  border-bottom: 1px solid #0c204d;
  height: 30px;
  line-height: 30px;
  position: relative;
  padding-left: 15px;
}

.baseTitle::after {
  display: block;
  content: "";
  height: 30px;
  width: 5px;
  position: absolute;
  left: 0;
  top: 0;
  background: #0c204d;
}

/* 弹框 */
.publicForm {
  display: flex;
}

.publicForm .mouldForm /deep/ .el-form-item__content {
  margin-left: 120px !important;
}

.publicFormBox {
  width: 50%;
  height: 100%;
}

.closure /deep/ .el-input__suffix {
  left: 91%;
}

// 树弹框
#department1 /deep/ .el-dialog {
  width: 600px !important;
}

// 树弹框

/* 弹框 */
</style>